<template>
    <div class="newsInfo-container">
        <h3 class="title"> {{newsInfo.title}} </h3>
        <p class="subtitle">
            <span>发表时间：{{newsInfo.add_time | dateFormat}}</span>
            <span>点击：{{newsInfo.click}}次</span>
        </p>
        <hr>
        <div class="content" v-html="newsInfo.content">
            <!-- 内容中有html标签，所以用v-html命令来渲染最好-->
            <!-- {{ newsInfo.content }} -->
        </div>
        <comment-box :id="this.id"></comment-box>
    </div>
</template>
<script>
import {Toast} from 'mint-ui'
import comment from '../subcomponents/commont.vue'   //导入评论子组件

export default {
   data() {
       return {
           id: this.$route.params.id,   //将url地址中传递过来的id值，挂载到data上，方便调用
           newsInfo:{}
       }
   },
   created(){
       this.getNewsInfo()
   },
   methods:{
       getNewsInfo() {
           this.$http.get('http://www.liulongbin.top:3005/api/getnew/' + this.id).then( result=> {
            //    console.log(result.body)
                if(result.body.status === 0){
                    this.newsInfo = result.body.message[0]
                } else {
                    Toast('获取新闻详情失败')
                }
           })
       }
   },
   components:{
       'comment-box': comment
   } 
}
</script>
<style lang="scss">
    .newsInfo-container{
        padding: 0 4px;
        .title{
            font-size:16px;
            text-align: center;
            margin:15px 0;
            color: red;
        }
        .subtitle{
            font-size:13px;
            color:#226aff;
            display: flex;
            justify-content:space-between;
        }
        .content{
            img{
                width:100%;
            }
        }
    }
</style>


